package com.situ.dao;

import com.situ.util.DBUtil;
import com.situ.vo.MenuTreeVO;
import com.situ.vo.MenuVO;

import java.util.List;

public class MenuDao {
    public List<MenuVO> select() {
        return DBUtil.executeDQL("select * from menu", MenuVO.class);
    }

    public List<MenuTreeVO> selectMenu(Integer rid, Integer pid) {
        return DBUtil.executeDQL("select menu.id,name 'title',role_menu.id 'checked' from menu left join role_menu on menu.id = role_menu.menu_id and role_menu.role_id = ? where parent_id = ?", MenuTreeVO.class, rid, pid);
    }

    public List<MenuTreeVO> selectMenu2(Integer id, Integer pid) {
        String sql = "SELECT DISTINCT menu.id,NAME 'title',icon,href FROM menu INNER JOIN role_menu ON menu.id=role_menu.menu_id INNER JOIN user_role ON user_role.role_id=role_menu.role_id WHERE parent_id=? AND user_role.user_id=?";
        return DBUtil.executeDQL(sql, MenuTreeVO.class, pid, id);
    }
}
